const app = getApp()
const aa = require('../../utils/m1')

Page({
  data: {
    info: {
      title: 'hi'
    },
    app: {
      title: app.info.title
    },
    fruits: [
      '苹果',
      '葡萄',
      '沙果'
    ],

    xxx: {
      aaa: 100,
      bbb: 200,
      ccc: 300
    }
  },

  onShow() {
    console.log(app.info.title)
    app.setTitle('world')
    // console.log(app.info.title)
  },

  handleTap() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },


  onLoad: function(options) {
    // 页面创建时执行
    console.log(options)
  },
  onShow: function() {
    // 页面出现在前台时执行
    console.log(100)

    console.log(aa)
  },
  onReady: function() {
    // 页面首次渲染完毕时执行
    console.log('onReady')

    wx.onCompassChange(function (res) {
      console.log(res.direction)
    })
    
  },
  onHide: function() {
    // 页面从前台变为后台时执行
    console.log(200)
  },
  onUnload: function() {
    // 页面销毁时执行
  },

  onPullDownRefresh: function() {
    // 触发下拉刷新时执行
    console.log('pulling')
  },

  onReachBottom: function() {
    // 页面触底时执行
    console.log('reached bottom')
  },

  onShareAppMessage: function () {
    // 页面被用户分享时执行
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '自定义转发标题'
        })
      }, 2000)
    })
    return {
      title: 'hello',
      path: '/page/index/index',
      promise
    }
  },

  onPageScroll: function() {
    // 页面滚动时执行
    console.log(0)
  },

  onResize: function() {
    // 页面尺寸变化时执行
    console.log('onResize')
  },

  onTabItemTap() {
    console.log('enter')
  },

  handleChange() {
    console.log(this.abc.x)
    this.setData({
      info: {
        title: 'haha'
      }
    })
  },

  abc: {
    x: 100
  },

  handleGotoButton() {
    wx.navigateTo({
      url: '/pages/profile/profile',
    })

    // wx.switchTab({
    //   url: '/pages/search/search',
    // })
  }
  
})